********************************************************************************
**************************  FIGURE 3  ******************************************
*************The Effects of Formal Leadership on Women's Influence**************
********************************************************************************

clear all
set more off

//cd "C:/Users/ganth/Dropbox/StrengthInNumbersReplicationPackage/replicable/figure_3"

*ssc install outreg2, replace

********************************************************************************

***Figure 3a***


**Study 2 Analysis
*Task 1 
use "figure_3_dataset.dta", clear
reg genderminfl_ratio_r1 i.condition_2f, robust
margins condition_2f, post
local minfl_majmen = r(table)[1,2]
local minfl_majmen_se = r(table)[2,2]
qui sum genderminfl_ratio_r1 if condition_2f==1
local minfl_majmen_n = r(N)
local minfl_majmen_sd = `minfl_majmen_se' * sqrt(`minfl_majmen_n')
estimates store margins
test _b[1.condition_2f] = _b[0.condition_2f]
outreg2 margins using "intermediate_data/study2_newfig_groupgenderminfl_ratio_r1.dta", replace dta side noparen noas

ttest genderminfl_ratio_r1 if condition_2f==0 | condition_2f==1, by(condition_2f)
putexcel set "intermediate_data/study2_newfig_groupgenderminfl_ratio_r1p.xlsx", sheet("t_test") replace
putexcel A1=("group1") B1= ("group2") C1=("p") D1=("y.position")
putexcel A2 = (0.75)
putexcel B2 = (2.25)
putexcel C2 = (round(r(p), 0.001))
putexcel D2 = 1.25
putexcel save

use "intermediate_data/study2_newfig_groupgenderminfl_ratio_r1_dta.dta", clear
drop if v3==""
drop if v3=="(2)"	
drop if v3=="se"
destring v2 v3, replace
replace v1="Majority Male" if v1=="1.condition_2f"
replace v1="Majority Female" if v1=="0bn.condition_2f"
gen ci=v3*1.96
export delimited "intermediate_data/study2_newfig_groupgenderminfl_ratio_r1_forgraphing.csv", replace


*Task 2 Male Leader
use "figure_3_dataset.dta", clear
reg genderminfl_ratio_r2 i.condition_2f if fem_leader == 0, robust
margins condition_2f, post
estimates store margins
test _b[1.condition_2f] = _b[0.condition_2f]
outreg2 margins using "intermediate_data/study2_newfig_groupgenderminfl_ratio_r2_male.dta", replace dta side noparen noas

ttest genderminfl_ratio_r2 if (fem_leader == 0) & (condition_2f==0 | condition_2f==1), by(condition_2f)
putexcel set "intermediate_data/study2_newfig_groupgenderminfl_ratio_r2_malep.xlsx", sheet("t_test") replace
putexcel A1=("group1") B1= ("group2") C1=("p") D1=("y.position")
putexcel A2 = (0.75)
putexcel B2 = (2.25)
putexcel C2 = (round(r(p), 0.001))
putexcel D2 = 1.25
putexcel save

use "intermediate_data/study2_newfig_groupgenderminfl_ratio_r2_male_dta.dta", clear
drop if v3==""
drop if v3=="(2)"
drop if v3=="se"
destring v2 v3, replace
replace v1="Majority Male" if v1=="1.condition_2f"
replace v1="Majority Female" if v1=="0bn.condition_2f"
gen ci=v3*1.96
export delimited "intermediate_data/study2_newfig_groupgenderminfl_ratio_r2_male_forgraphing.csv", replace


*Task 2 Female Leader
use "figure_3_dataset.dta", clear
reg genderminfl_ratio_r2 i.condition_2f if fem_leader == 1, robust
margins condition_2f, post
local minfl_majmenf = r(table)[1,2]
local minfl_majmenf_se = r(table)[2,2]
qui sum genderminfl_ratio_r2 if condition_2f==1 & fem_leader == 1
local minfl_majmenf_n = r(N)
local minfl_majmenf_sd = `minfl_majmenf_se' * sqrt(`minfl_majmenf_n')
estimates store margins
test _b[1.condition_2f] = _b[0.condition_2f]
outreg2 margins using "intermediate_data/study2_newfig_groupgenderminfl_ratio_r2_fem.dta", replace dta side noparen noas
reg leaderminfl_ratio_r2 i.condition_2f if fem_leader == 1, robust
margins condition_2f, post
estimates store margins
test _b[1.condition_2f] = _b[0.condition_2f]
outreg2 margins using "intermediate_data/study2_newfig_groupleaderminfl_ratio_r2_fem.dta", replace dta side noparen noas

ttest genderminfl_ratio_r2 if (fem_leader == 1) & (condition_2f==0 | condition_2f==1), by(condition_2f)
putexcel set "intermediate_data/study2_newfig_groupgenderminfl_ratio_r2_femp.xlsx", sheet("t_test") replace
putexcel A1=("group1") B1= ("group2") C1=("p") D1=("y.position")
putexcel A2 = (0.75)
putexcel B2 = (2.25)
putexcel C2 = (round(r(p), 0.001))
putexcel D2 = 1.25
putexcel save

use "intermediate_data/study2_newfig_groupleaderminfl_ratio_r2_fem_dta.dta", clear
drop if v3==""
drop if v3=="(2)"
drop if v3=="se"
destring v2 v3, replace
replace v1="Majority Male" if v1=="1.condition_2f"
replace v1="Majority Female" if v1=="0bn.condition_2f"
gen v5 = v1 + " (L)"
drop v3
rename v2 v4
tempfile leaderminfl
save `leaderminfl'

use "intermediate_data/study2_newfig_groupgenderminfl_ratio_r2_fem_dta.dta", clear
drop if v3==""
drop if v3=="(2)"
drop if v3=="se"
destring v2 v3, replace
replace v1="Majority Male" if v1=="1.condition_2f"
replace v1="Majority Female" if v1=="0bn.condition_2f"
gen ci=v3*1.96
merge 1:1 v1 using `leaderminfl', nogen
gen v6 = v2
replace v2 = v2-v4
keep v1 v2 v3 v6 ci
gen v5=v1
append using `leaderminfl'
replace v2 = v4 if v2==.
drop v4
export delimited "intermediate_data/study2_newfig_groupgenderminfl_ratio_r2_fem_forgraphing.csv", replace

clear

***Figure 3b***
use "figure_3_dataset.dta", clear
reg genderspokes_ratio_r1 i.condition_2f, robust
margins condition_2f, post
estimates store margins
test _b[1.condition_2f] = _b[0.condition_2f]
outreg2 margins using "intermediate_data/study2_newfig_groupgenderspokes_ratio_r1.dta", replace dta side noparen noas

ttest genderspokes_ratio_r1 if condition_2f==0 | condition_2f==1, by(condition_2f)
putexcel set "intermediate_data/study2_newfig_groupgenderspokes_ratio_r1p.xlsx", sheet("t_test") replace
putexcel A1=("group1") B1= ("group2") C1=("p") D1=("y.position")
putexcel A2 = (0.75)
putexcel B2 = (2.25)
putexcel C2 = (round(r(p), 0.001))
putexcel D2 = 1.4
putexcel save

use "intermediate_data/study2_newfig_groupgenderspokes_ratio_r1_dta.dta", clear
drop if v3==""
drop if v3=="(2)"
drop if v3=="se"
destring v2 v3, replace
replace v1="Majority Male" if v1=="1.condition_2f"
replace v1="Majority Female" if v1=="0bn.condition_2f"
gen ci=v3*1.96
export delimited "intermediate_data/study2_newfig_groupgenderspokes_ratio_r1_forgraphing.csv", replace


*Task 2 Male Leader
use "figure_3_dataset.dta", clear
reg genderspokes_ratio_r2 i.condition_2f if fem_leader == 0, robust
margins condition_2f, post
estimates store margins
test _b[1.condition_2f] = _b[0.condition_2f]
outreg2 margins using "intermediate_data/study2_newfig_groupgenderspokes_ratio_r2_male.dta", replace dta side noparen noas

ttest genderspokes_ratio_r2 if (fem_leader == 0) & (condition_2f==0 | condition_2f==1), by(condition_2f)
putexcel set "intermediate_data/study2_newfig_groupgenderspokes_ratio_r2_malep.xlsx", sheet("t_test") replace
putexcel A1=("group1") B1= ("group2") C1=("p") D1=("y.position")
putexcel A2 = (0.75)
putexcel B2 = (2.25)
putexcel C2 = (round(r(p), 0.001))
putexcel D2 = 1.4
putexcel save

use "intermediate_data/study2_newfig_groupgenderspokes_ratio_r2_male_dta.dta", clear
drop if v3==""
drop if v3=="(2)"
drop if v3=="se"
destring v2 v3, replace
replace v1="Majority Male" if v1=="1.condition_2f"
replace v1="Majority Female" if v1=="0bn.condition_2f"
gen ci=v3*1.96
export delimited "intermediate_data/study2_newfig_groupgenderspokes_ratio_r2_male_forgraphing.csv", replace


*Task 2 Female Leader
use "figure_3_dataset.dta", clear
reg genderspokes_ratio_r2 i.condition_2f if fem_leader == 1, robust
margins condition_2f, post
estimates store margins
test _b[1.condition_2f] = _b[0.condition_2f]
outreg2 margins using "intermediate_data/study2_newfig_groupgenderspokes_ratio_r2_fem.dta", replace dta side noparen noas
reg leaderspokes_ratio_r2 i.condition_2f if fem_leader == 1, robust
margins condition_2f, post
estimates store margins
test _b[1.condition_2f] = _b[0.condition_2f]
outreg2 margins using "intermediate_data/study2_newfig_groupleaderspokes_ratio_r2_fem.dta", replace dta side noparen noas

ttest genderspokes_ratio_r2 if (fem_leader == 1) & (condition_2f==0 | condition_2f==1), by(condition_2f)
putexcel set "intermediate_data/study2_newfig_groupgenderspokes_ratio_r2_femp.xlsx", sheet("t_test") replace
putexcel A1=("group1") B1= ("group2") C1=("p") D1=("y.position")
putexcel A2 = (0.75)
putexcel B2 = (2.25)
putexcel C2 = (round(r(p), 0.001))
putexcel D2 = 1.4
putexcel save

use "intermediate_data/study2_newfig_groupleaderspokes_ratio_r2_fem_dta.dta", clear
drop if v3==""
drop if v3=="(2)"
drop if v3=="se"
destring v2 v3, replace
replace v1="Majority Male" if v1=="1.condition_2f"
replace v1="Majority Female" if v1=="0bn.condition_2f"
gen v5 = v1 + " (L)"
drop v3
rename v2 v4
tempfile leaderspokes
save `leaderspokes'

use "intermediate_data/study2_newfig_groupgenderspokes_ratio_r2_fem_dta.dta", clear
drop if v3==""
drop if v3=="(2)"
drop if v3=="se"
destring v2 v3, replace
replace v1="Majority Male" if v1=="1.condition_2f"
replace v1="Majority Female" if v1=="0bn.condition_2f"
gen ci=v3*1.96
merge 1:1 v1 using `leaderspokes', nogen
gen v6 = v2
replace v2 = v2-v4
keep v1 v2 v3 v6 ci
gen v5=v1
append using `leaderspokes'
replace v2 = v4 if v2==.
drop v4
export delimited "intermediate_data/study2_newfig_groupgenderspokes_ratio_r2_fem_forgraphing.csv", replace

